package domain.controller;

import java.io.IOException;
import java.net.URLDecoder;
import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import domain.data.QnAPersistenceManager;
import domain.model.Whois;
import domain.service.Utils;

@SuppressWarnings("serial")
public class ExpirationServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html");
        resp.getWriter().println("Hello, world");
        Date date_cache = new Date(new Date().getTime()+60*60*1000);
		
		resp.setHeader( "Cache-Control", "public, max-age=30");
		resp.setHeader( "Expires", date_cache.toGMTString() );
//        PersistenceManager psm = QnAPersistenceManager.get().getPersistenceManager();
//        
//        String path = ((HttpServletRequest)req).getRequestURI();
//		StringTokenizer st = new StringTokenizer( path,"/");
//        int count = st.countTokens(); 
//
//        if(count != 2)
//        {
//        	resp.sendRedirect("/");
//        }
//        
//		// skip one token /question/abcd (remove sites)
//		st.nextToken();
//		String title_url = st.nextToken();
//		title_url=URLDecoder.decode(title_url,"UTF-8");
//		Query query = psm.newQuery(Whois.class);
//		query.setFilter("expirationDate =='"+title_url+"'");
//		query.setRange(0,100);
//		@SuppressWarnings("unchecked")
//		List<Whois> listEmails = (List<Whois>) query.execute();
//		req.setAttribute("listEmails", listEmails);
//		req.setAttribute("email", "Expiration Date : "+title_url);
//		
//		req.setAttribute("title", "Expiration Date - "+title_url);
//		req.setAttribute("description", "Expiration Date - "+title_url+"the website of the same Expiration Date "+title_url+" is synthesized by  "+Utils.ValidDomain());
//		req.setAttribute("keyword", title_url+",linkout,Domain name information,  Server information, Web site analysis, website traffic details, Website backlinks website IP, website ranking info,topic");
//		
//		try {
//			req.getRequestDispatcher("/ower.jsp").forward(req, resp);
//		} catch (ServletException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
    }

}
